import matplotlib.pyplot as plt
import numpy as np
from PIL import Image

# 打开当前目录图像并转化为数字矩阵，调用numpy中的array（）函数就可以将PIL对象转换为数组对象
img_open = Image.open('zmg.jpeg')
img = np.array(img_open)

# 随机生成5000个随机噪声点
rows, cols, dims = img.shape
for i in range(5000):
    x = np.random.randint(0, rows)
    y = np.random.randint(0, cols)
    img[x, y, :] = 255

plt.figure("zmg")
plt.imshow(img)
plt.axis('off')
plt.show()
